package com.cn.intelligence.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.intelligence.pojo.EUDataGridResult;
import com.cn.intelligence.pojo.TaotaoResult;
import com.cn.intelligence.pojo.TbItem;
import com.cn.intelligence.service.ItemService;

@Controller
@RequestMapping("/item/")
public class ItemController {
    @Autowired
    private ItemService itemService;
    
    /**
     * 获取商品详情
     * @param itemId
     * @return
     */
    @RequestMapping("{itemId}")
    @ResponseBody
    public TbItem getItemById(@PathVariable Long itemId) {
        TbItem tbItem = itemService.getItemById(itemId);
        return tbItem;
    }
    /**
     * 获取商品图片信息详情
     * @param itemId
     * @return
     */
    @RequestMapping("getItemPhotoXById/{itemId}")
    @ResponseBody
    public TbItem getItemPhotoXById(@PathVariable Long itemId) {
        TbItem tbItem = itemService.getItemPhotoXById(itemId);
        return tbItem;
    }

    /**
     * 查询商品列表
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public EUDataGridResult getItemList(Integer page,Integer rows,String selectPoint,String selectName,String selectpinpai){
        EUDataGridResult euDataGridResult =itemService.getItemList(page,rows,selectPoint,selectName,selectpinpai);
        return euDataGridResult;
    }
    /**
     * 保存商品信息
     */
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult saveItem(TbItem item,String desc,String itemParams) throws Exception {
        TaotaoResult taotaoResult= itemService.saveItem(item,desc,itemParams);
        return taotaoResult;
    }
    /**
     * 修改商品信息
     */
    @RequestMapping(value = "edit",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult editItem(TbItem item,String desc,String itemParams) throws Exception {
        TaotaoResult taotaoResult= itemService.editItem(item,desc,itemParams);
        return taotaoResult;	
    }
    /**
     * 删除该商品delete
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult deleteItem(Long ids[]) throws Exception {
        TaotaoResult taotaoResult= itemService.deleteItem(ids);
        return taotaoResult;
    }
    /**
     * 删除该商品delete
     */
    @RequestMapping(value = "instock",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult instockItem(Long ids[]) throws Exception {
        TaotaoResult taotaoResult= itemService.instockItem(ids);
        return taotaoResult;
    }
    /**
     * 删除该商品delete
     */
    @RequestMapping(value = "reshelf",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult reshelfItem(Long ids[]) throws Exception {
        TaotaoResult taotaoResult= itemService.reshelfItem(ids);
        return taotaoResult;
    }
    /**
     * 将商品推荐到首页
     */
    @RequestMapping(value = "pushhome",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult pushhomeItem(Long ids[],String stortOrder) throws Exception {
        TaotaoResult taotaoResult= itemService.pushhomeItem(ids,stortOrder);
        return taotaoResult;
    }
    /**
     * 将商品取消推荐到首页
     */
    @RequestMapping(value = "popHome",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult popHomeItem(Long ids[],String stortOrder) throws Exception {
        TaotaoResult taotaoResult= itemService.popHomeItem(ids,stortOrder);
        return taotaoResult;
    }
}
